package com.tc.controller;


import com.tc.common.response.Response;
import com.tc.domain.dataobject.Order;
import com.tc.model.dto.UserAndAmountInfoDTO;
import com.tc.service.OrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Resource
    private OrderService orderService;
    @PostMapping("allpay")
    private Response<?> findAllPay(){
        // 查询所有已支付订单，按金额降序排序
        List<Order> allPaidOrdersDESC = orderService.findAllPaidOrdersDESC();
        return Response.success(allPaidOrdersDESC);
    }

    @PostMapping("allmoney")
    private Response<?> findSumByUserId(){
        // 查询每个用户的总订单金额，返回 Map<用户ID, 总金额>。
        List<UserAndAmountInfoDTO> allOrdersAndUserId = orderService.findAllOrdersAndUserId();
        return Response.success(allOrdersAndUserId);
    }


    @PostMapping("top3")
    private Response<?> find3ordersRecent(){
        // 按用户ID分组，列出每个用户最近3笔订单。
        List<Order> orders = orderService.top3ByUserId();
        return Response.success(orders);
    }


    @PostMapping("top7")
    private Response<?> find7DaysOrderSum(){
        // 查询近7天内产生的订单总数。
        Long orderNums = orderService.sum7days();
        return Response.success(orderNums);

    }

    @PostMapping("`top5`")
    private Response<?> findTop5Money(){
        // 找到金额Top5的订单。
        List<Order> orders = orderService.top5ByAmount();
        return Response.success(orders);
    }


}
